﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace CFG
{
    class Program
    {
        //private DateTime time;
        /// <summary>
        /// 分布式计算的同步step
        /// </summary>
        public int stepForShow = 0;

        //private Allocation allo = new Allocation();
        /// <summary>
        /// 主程序入口
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Allocation allo = new Allocation();
            DateTime time;
            int stepForShow = 0;
            string f = "h:\\programming Data\\Data\\G05\\NO3";
            allo.center = new Location();
            allo.center.lat = 400;
            allo.center.lot = 300;
            allo.Initial_Task(f);
            allo.Initial_Agents(f);
            int step;
            int formStep,nowStep;
            int interval = 0; //时间间隔
            double fls = 0;
            //设置基准时间
            time = System.DateTime.Now;
            step = time.Hour*3600 + time.Minute * 60 + time.Second;
            formStep = step;
            do
            {
                time = System.DateTime.Now;
                nowStep = time.Hour*3600+ time.Minute * 60 + time.Second;
                interval = nowStep - formStep;               
                if (interval >=1)
                {
                    stepForShow = nowStep - step;
                    allo.Agent_Assignment(stepForShow);
                    //Repaint();                    
                }
                formStep = nowStep;  
            } while (allo.task_Pending.Count != 0 || allo.task_Waiting.Count !=0 || allo.task_UnderGoing.Count!=0);
            fls = (allo.distance.ablityX + allo.distance.ablityY) / (allo.totalAblity.ablityX + allo.totalAblity.ablityY);
            allo.TaskInfo += fls.ToString();
            //File.WriteAllText("h:\\programming Data\\Result\\自适应试验数据分析\\对比组试验\\G05\\NO3\\taskResult对比01.csv", allo.TaskInfo);
            //File.WriteAllText("h:\\programming Data\\Result\\自适应试验数据分析\\对比组试验\\G05\\NO3\\agentResult对比01.csv", allo.AgentInfo);
            File.WriteAllText("h:\\programming Data\\Result\\自适应试验数据分析\\Self-Adaption in Net\\G05\\NO3\\taskResult01.csv", allo.TaskInfo);
            File.WriteAllText("h:\\programming Data\\Result\\自适应试验数据分析\\Self-Adaption in Net\\G05\\NO3\\agentResult01.csv", allo.AgentInfo);
            Console.WriteLine("End");
            Console.WriteLine(fls.ToString());
            Console.ReadLine();
        }       
     }
}
